<html>
<base href="http://${pageContext.request.serverName}:${pageContext.request.serverPort}${pageContext.request.contextPath}/">
<script type="text/javascript" src="jquery/jquery-2.1.1.min.js"></script>
<script type="text/javascript">
    $(function () {

        $("#btn3").click(function () {
            var student = {
                "stuId": 5,
                "stuName": "tom",
                "address": {
                    "province": "shanghai",
                    "city": "putuo",
                    "street": "shifan"
                },
                "subjectList": [
                    {
                        "subjectName": "javaSe",
                        "subjectScore": 99
                    },
                    {
                        "subjectName": "ssm",
                        "subjectScore": 93
                    },
                ],
                "map": {
                    "k1": "v1",
                    "k2": "v2"
                }
            }

            var res = JSON.stringify(student)

            $.ajax({
                "url": "send/compose/object.json",
                "type": "post",
                "data": res,
                "contentType":"application/json;charset=UTF-8",
                "dataType":"json",
                "success":function (response){
                    console.log(response.data)
                },
                "error":function (response){
                    console.log(response.data)
                }
            })
        })

        // 准备好要发送服务器端的数组
        var array = [1, 2, 3]
        // 将json数组转换称为json字符串
        var res = JSON.stringify(array)

        $("#btn2").click(function () {
            $.ajax({
                "url": "send/array.html/one.html", // 请求目标资源的地址
                "type": "post", // 请求方式
                "data": res,   // 发送请求的参数
                "contentType": "application/json;charset=UTF-8", // 告诉服务器端当前请求的请求体是 JSON 格式
                "dataType": "text", // 服务段返回的数据
                "success": function (response) { // 服务器请求成功的调用的回调函数
                    alert(response)
                },
                "error": function (response) {
                    alert(response)
                }
            })
        })

        $("#btn1").click(function () {
            $.ajax({
                "url": "send/array.html", // 请求目标资源的地址
                "type": "post", // 请求方式
                "data": {
                    "array": [1, 2, 3]
                },   // 发送请求的参数
                "dataType": "text", // 服务段返回的数据
                "success": function (response) { // 服务器请求成功的调用的回调函数
                    alert(response)
                },
                "error": function (response) {
                    alert(response)
                }
            })
        })
    })
</script>
<body>
<a href="test/ssm.html">测试smm</a>
<br/>
<button id="btn1">Send [1,2,3] one</button>
<button id="btn2">Send [1,2,3] one</button>
<button id="btn3">Send Compose Object</button>
</body>
</html>
